initialiseADConverter

Owner: Michelle

Purpose and Documentation

This is part of the setup routine, which will enable the AD converstion.

Syntax

void initialise_AD_Converter()

Usage

This function should be called from the setup() function during the initialisation of the program.

Input Arguments

  • void. This function takes no arguments.

Output Arguments

  • None. This function does not make changes to any existing values.

Return Value

  • void.

Settings and Registers

Read

  • None

Write

  • ADCON0
  • ADCON1
  • T0CON
  • INTCONbits.TMR0IF

Operation

Enable A/D, synchronise to clock. Use all of ADRESL and part of ADRESH to store result, use board voltage references (needs to be changed). Enable T0.

Code

/**
 * Intitialises the A/D converter, and waits until the A/D converter has finished enabling.
 * Postcondition: The A/D converter is enabled.
 */
void initialiseADConverter()
{
    ADCON0 = 0b01000001; //Fosc/8, A/D enabled
    ADCON1 = 0b10001110; //Right justify, 1 analog channel; VDD and VSS references
    T0CON  = 0b11000111; //TMR0 prescaler, 1:256
    while(INTCONbits.TMR0IF == 0);
    INTCONbits.TMR0IF = 0;
}